<!-- 卡项选择弹出窗 -->
<template>
	<div>
		<el-dialog title="储值卡选择" v-model="state.isShowDialog" width="1100px">
            <section>
				<el-form ref="roleDialogFormRef"    label-width="80px">
					<el-row :gutter="35">
						<el-col :span="7" class="mb20">
							<el-form-item label="查询方式">
								<el-select v-model="state.param.searchType" placeholder="请选择门店类型" class="w100">
									<el-option v-for="item in state.query.searchType" :key="item.value"
										:label="item.label" :value="item.value" />
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="7" class="mb20">
							<el-form-item label="商品分类">
								<el-input  placeholder="请输入关键字搜索" clearable></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="7" class="mb20">
							<el-form-item label="信息搜索">
								<el-input placeholder="请输入关键字搜索" clearable></el-input>
							</el-form-item>
						</el-col>
						<el-col :span="3" class="mb20">
							<el-button type="primary" @click="search()">
								<el-icon> <ele-Search /> </el-icon> 搜 索
							</el-button>
						</el-col>
					</el-row>
				</el-form>
            </section>
			<div class="cropper-warp">
				<el-table :data="state.goodsTableData" style="width: 100%;">
                    <el-table-column type="selection" width="55" />
                    <el-table-column prop="id" label="ID" width="80" />
                    <el-table-column label="图片" show-overflow-tooltip width="80">
						<template #default="scope">
							<el-image style="width:32px; height: 32px;"
								src="https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500"
								fit="cover" />
						</template>
					</el-table-column>
                    <el-table-column prop="title" label="商品名称" show-overflow-tooltip>
						<template #default="scope">
							<span>{{ scope.row.name }}</span>
						</template>
					</el-table-column>
                    <el-table-column prop="id" label="零售价" show-overflow-tooltip></el-table-column>
                </el-table>
                <el-row justify="end">
                    <el-col :span="24" class="flex-end-center">
                        <el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
                            :pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="state.param.pageNum" background
                            v-model:page-size="state.param.pageSize" layout="total, sizes, prev, pager, next, jumper"
                            :total="state.total">
                        </el-pagination>
                    </el-col>
                </el-row>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel"   >取 消</el-button>
					<el-button type="primary" @click="onSubmit"   >确 认</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script setup lang="ts" name="cropper">
import { reactive, nextTick } from 'vue';
import { productList } from '/@/api/commodity';
// 定义变量内容
const state = reactive({
	isShowDialog: false,
	cropperImgBase64: '',
    param: {
		searchType : 1,
		keyword: "",
		pageNum: 1,
		pageSize: 10,  
	},
	query:{
		searchType: [
			{ value: 1, label: 'SPU查询' },
			{ value: 1, label: 'SKU查询' }
		]
	},
    total: 0,
    goodsTableData:[],
});

// 打开弹窗
const openDialog = () => {
	state.isShowDialog = true;
	nextTick(() => {
		getGoodsList();
	});
};
// 关闭弹窗
const closeDialog = () => {
	state.isShowDialog = false;
};
// 取消
const onCancel = () => {
	closeDialog();
};
// 更换
const getGoodsList = async() => {
    state.loading = true;
	const { results } = await productList(state.param);
	state.loading = false;
	state.goodsTableData = results.records;
	state.total = results.total;
};

// 分页点击条数
const onHandleSizeChange = (val: number) => {
	state.param.pageSize = val;
    getGoodsList();
};
// 分页点击
const onHandleCurrentChange = (val: number) => {
	state.param.pageNum = val;
    getGoodsList();
}

// 暴露变量
defineExpose({
	openDialog,
});
</script>

<style scoped lang="scss">
.cropper-warp {
	.cropper-warp-left {
		position: relative;
		display: inline-block;
		height: 350px;
		flex: 1;
		border: 1px solid var(--el-border-color);
		background: var(--el-color-white);
		overflow: hidden;
		background-repeat: no-repeat;
		cursor: move;
		border-radius: var(--el-border-radius-base);
		.cropper-warp-left-img {
			width: 100%;
			height: 100%;
		}
	}
	.cropper-warp-right {
		width: 150px;
		height: 350px;
		.cropper-warp-right-title {
			text-align: center;
			height: 20px;
			line-height: 20px;
		}
		.cropper-warp-right-item {
			margin: 15px 0;
			.cropper-warp-right-value {
				display: flex;
				.cropper-warp-right-value-img {
					width: 100px;
					height: 100px;
					border-radius: var(--el-border-radius-circle);
					margin: auto;
				}
				.cropper-size {
					width: 50px;
					height: 50px;
				}
			}
			.cropper-warp-right-label {
				text-align: center;
				font-size: 12px;
				color: var(--el-text-color-primary);
				height: 30px;
				line-height: 30px;
			}
		}
	}
}
</style>
